/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utilities;

import algorithms.L1Metric;
import algorithms.MutualEntropy;
import comparators.SortNodeDepsByDep;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
import structure.NodeDependency;
import structure.Variable;

/**
 *
 * @author Richard
 */
public class WriteMutualEntropy {
    private static ArrayList<NodeDependency> sortList = new ArrayList<NodeDependency>();

    public static void Write(String input) throws FileNotFoundException, IOException{
        ArrayList<Variable> variables1 = StringParse.data.getVariables();
        ArrayList<Variable> variables2 = variables1;

        String finalString = "Testing Mutual Entropy : " + input +
                             "\n-----------------------------------------------------------------------\n\n";

        for (Variable v1 : variables1) {
            for (Variable v2 : variables2) {
                if (v1.getId() != v2.getId()) {
                    System.out.println("\nVariables: " + v1.getId() + " and " + v2.getId());
                    double calc = MutualEntropy.calculate(v1, v2);
                    sortList.add(new NodeDependency(v1,v2,calc));
                }
            }
        }
        Collections.sort(sortList, new SortNodeDepsByDep());
        for(NodeDependency ndep : sortList){
            finalString = finalString + "ARC FOUND: Variable " + ndep.getFirst().getId() + " To Variable" + ndep.getSecond().getId() + " : Mutual Entropy = " + ndep.getDependency() + "\n";
        }

        finalString = finalString + "\n\n Completed...";

        File outFile = new File("out_entropy_"+input);
        if (!outFile.exists()) {
            outFile.createNewFile();
        }
        TextFile.setContents(outFile, finalString);
    }

    public static ArrayList<NodeDependency> getSortedList(){
        return sortList;
    }
}
